package com.kaifamiao.repository;

import com.kaifamiao.entity.FileInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface FileRepository extends JpaRepository<FileInfo, Integer> {

    // Spring Data 会根据方法名自动生成查询语句
    List<FileInfo> findByUploaderId( Integer userId );

    // JPQL: Java Persistence Query Language
    @Query("FROM FileInfo fi WHERE fi.uploader.id = :userId")
    List<FileInfo> loadMyFiles(Integer userId);

    // Spring Data 会根据方法名自动生成查询语句
    List<FileInfo> findByUploaderIdIsNot( Integer userId );

    // JPQL: Java Persistence Query Language
    @Query("FROM FileInfo fi WHERE fi.uploader.id <> :userId")
    List<FileInfo> loadOtherFiles(Integer userId);


}
